<?php //VSIA ETA HUJNIA DLIA PERENOSKI DANNYH?>
<?php require_once("includes/connection.php"); ?>

<?php

	$query = "SELECT *";
	$query .= " FROM `templovos`";
	// $query .= " WHERE `user`.userid =";
	// $query .= "'".$_GET['userid']."'";
	$result = mysql_query($query, $connection);
	
	echo $query."<br>";	

do { 

	$query = "SELECT *";
			$query .= " FROM `lovos`";
			$query .= " WHERE `lovos`.burys =";
			$query .= "'".$subject['burys']."'";
			$query .= " AND `lovos`.brigada =";
			$query .= "'".$subject['brigada']."'";
			$query .= " AND `lovos`.lova =";
			$query .= "'".$subject['lova']."'";
			
			echo $query.'<br>';
		
			
			$result_set = mysql_query($query, $connection);
			$lovosid = mysql_fetch_array($result_set);
			
	
	
	$query = "SELECT *";
			$query .= " FROM `user`";
			$query .= " WHERE `user`.bylosnr =";
			$query .= "'".$subject['bylosnr']."'";
	
	$result_set = mysql_query($query, $connection);
			$lopas = mysql_fetch_array($result_set);
	
	
	
	echo $lopas['vardas']." ". $lopas['pavarde']." su bylos Nr: ".$subject['bylosnr']." gyvena lovoje Nr.:".$lovosid['lovosid']."<BR>";
				$sql = "UPDATE `user` SET ";
				$sql .= "lovosid=";
				$sql .= "'".($lovosid['lovosid'])."'";
				$sql .= " WHERE `user`.`userid` =";
				$sql .= $lopas['userid'];
				$update = mysql_query($sql, $connection);
					if (!$update) {
						// Display error message.
						$message .= "<p>Migracija table update failed</p>";
						$message .= "<p>" . mysql_error() . "</p>";
					}else{
						echo "VSIO KLASSSSS!!!<BR><BR>";
					};
	
	} while ($subject = mysql_fetch_assoc($result)); 	
				// $sql = "UPDATE `migracija` SET ";
				// $sql .= "kelimodata=";
				// $sql .= "'".($_POST['kelimodata'])."'";
				// $sql .= ", fromlovosid=";
				// $sql .= $fromlovosid;
				// $sql .= ", tolovosid=";
				// $sql .= $tolovosid;
				
				// $sql .= ", perkeltas=";
				
				// $sql .= " WHERE `migracija`.`migracijaid` =";
				// $sql .= $_GET['migracijaid'];
				// echo $sql;
				// $result = mysql_query($sql, $connection);
					// if (!$result) {
						// Display error message.
						// $message .= "<p>Migracija table update failed</p>";
						// $message .= "<p>" . mysql_error() . "</p>";
					// }else{
						// $to = "form_prekelimai.php";
						// redirect_to($to);
					// };
					
?>